package com.taoym.voucher.admin.controller;

import com.taoym.voucher.common.response.Response;
import com.taoym.voucher.admin.entity.dto.SysUpdateUserDTO;
import com.taoym.voucher.admin.entity.dto.SysUserLoginDTO;
import com.taoym.voucher.admin.entity.dto.SysUserRefreshTokenDTO;
import com.taoym.voucher.admin.entity.vo.SysGetUserDetailVO;
import com.taoym.voucher.admin.entity.vo.SysUserLoginVO;
import com.taoym.voucher.admin.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @coder taoym
 * @datetime 2021/7/7 17:18
 * @desc
 */
@Api(tags = "系统用户控制器")
@RestController
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation("系统用户登录")
    @PostMapping("/login")
    public Response<SysUserLoginVO> userLogin(@RequestBody @Valid SysUserLoginDTO data) {
        return Response.success(sysUserService.userLogin(data));
    }

    @ApiOperation("修改用户信息")
    @PostMapping("/update")
    public Response<Integer> updateUser(@RequestBody @Valid SysUpdateUserDTO data) {
        return Response.success(sysUserService.updateUser(data));
    }

    @ApiOperation("用户刷新token")
    @GetMapping("/refresh")
    public Response<String> refreshToken(@Valid SysUserRefreshTokenDTO data) {
        return Response.success(sysUserService.refreshToken(data));
    }

    @ApiOperation("用户个人详情信息")
    @GetMapping("/personal")
    public Response<SysGetUserDetailVO> personal() {
        return Response.success(sysUserService.personal());
    }

}
